package org.lanqiao.tjut.db;

import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSourceFactory;

/**
 * 获取数据库数据源使用dbcp数据库连接池进行管理
 * @author Administrator 
 *
 */
public class DBDataSource {
	private static DataSource dataSource;
	private DBDataSource(){
	}
	public static DataSource getDataSource(){
		if(dataSource==null){
			try{
				Properties prop=new Properties();
				prop.load(DBDataSource.class.getClassLoader().getResourceAsStream("db.properties"));
			    dataSource=BasicDataSourceFactory.createDataSource(prop);
			}catch (Exception e) {
				System.out.println("生成数据库连接池错误:"+e.getMessage());// TODO: handle exception
			}
		}
		return dataSource;
		
	}
	
}
